package com.skyline.spot.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.skyline.base.type.Activity;
import com.skyline.base.type.SpotRefrenceType;
import com.skyline.common.bean.Page;
import com.skyline.spot.dao.SpotRefrenceDao;
import com.skyline.spot.model.SpotRefrence;
import com.skyline.spot.service.SpotRefrenceService;

@Service("spotRefrenceService")
public class SpotRefrenceServiceImpl implements SpotRefrenceService {

	@Autowired
	private SpotRefrenceDao spotRefrenceDao;

	@Override
	public List<SpotRefrence> getRefrencesBySpotId(Long spotId,Page page){
		
		return spotRefrenceDao.queryRefrencesBySpotId(spotId, Activity.NORMAL,page);
	}

	@Override
	public SpotRefrence getRefrenceById(Long id) {
		return	spotRefrenceDao.queryRefrenceById(id, Activity.NORMAL);
		
	}
	@Override
	public List<SpotRefrence> getRefrencesBySpotIdAndType(Long spotId,
			SpotRefrenceType type,Page page){
		
		return spotRefrenceDao.queryRefrencesBySpotIdAndType(spotId, type,
				Activity.NORMAL,page);
	}

	@Override
	public List<SpotRefrence> getRefrenceByRefrenceIdAndSpotId(
			Long refrenceId, Long spotId,Page page){
		
		return spotRefrenceDao.queryRefrencesByRefrenceIdAndSpotId(refrenceId,
				spotId, Activity.NORMAL,page);
	}

	@Override
	public List<SpotRefrence> getRefrenceByRefrenceType(SpotRefrenceType type,Page page) {
		
		return spotRefrenceDao.queryRefrencesByType(type,
				Activity.NORMAL,page);
	}

	@Override
	public List<SpotRefrence> getRefrenceBySpotNameAndType(String spotName,
			SpotRefrenceType type,Page page) {
		
		return spotRefrenceDao.queryRefrencesBySpotNameAndType(spotName, type,
				Activity.NORMAL,page);
	}

	@Override
	public Long postToSpot(Long refrenceId,String refrencePortrait, String refrenceTitle,
			String refrenceDigest, SpotRefrenceType refrenceType, Long spotId,
			String spotName,String spotPortrait, Long providerId, String providerNickname,
			String providerPortrait, String providerEmail) {
		
		return spotRefrenceDao.insertRefrence(spotId, spotName,spotPortrait, refrenceId,refrencePortrait,
				refrenceTitle, refrenceDigest, refrenceType, providerId,
				providerNickname, providerPortrait, providerEmail);
	}

	@Override
	public void recoverRefrenceFromSpot(Long refrenceId, Long spotId) {
		
		spotRefrenceDao.deleteRefrenceByRefrenceIdAndSpotId(refrenceId, spotId);
	}

	@Override
	public void recoverRefrenceFromSpotByProviderId(Long providerId, Long spotId) {
		
		spotRefrenceDao.deleteRefrenceByProviderIdAndSpotId(providerId, spotId);
	}

	@Override
	public void recoverRefrenceFromSpotByProviderIdAndType(Long providerId,
			SpotRefrenceType type, Long spotId) {
		
		spotRefrenceDao.deleteRefrenceByProviderIdAndSpotIdAndType(providerId,
				spotId, type);
	}



}
